﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ev.CaiPiao
{
    class Task
    {
        /// <summary>
        /// 获取tokens
        /// </summary>
        /// <param name="loginId"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public string getToken(string loginId, string pwd)
        {
            try
            {
                var entity = new dbEntities();
                var model = entity.dl.FirstOrDefault(x => x.LoginId == loginId && x.Pwd == pwd);
                if (model != null && model.UID > 0)
                {
                    return model.Token;
                }
            }
            catch (Exception ex)
            {
                return "";
            }

            return "";
        }

        public dl loginUser(string loginId, string pwd)
        {
            try
            {
                var dbEntitiesContent = new dbEntities();
                var model = dbEntitiesContent.dl.FirstOrDefault(x => x.LoginId == loginId && x.Pwd == pwd);
                if (model != null && model.UID > 0)
                {
                    model.Token = DateTime.Now.ToString("yyyyMMddHHmmssfff") + new Random().Next(10000, 99999);
                    var ss = dbEntitiesContent.SaveChanges();
                    return model;
                }
            }
            catch (Exception ex)
            {
                
            }
            return null;
        }

    }
}
